/*
 * Copyright [duowan.com]
 * Web Site: http://www.duowan.com
 * Since 2005 - 2014
 */

package com.duowan.realtime.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import com.duowan.common.util.page.Page;
import com.duowan.realtime.dao.OverviewBloomfilterDao;
import com.duowan.realtime.model.OverviewBloomfilter;
import com.duowan.realtime.query.OverviewBloomfilterQuery;
import com.duowan.realtime.service.OverviewBloomfilterService;


/**
 * [OverviewBloomfilter] 的业务操作实现类
 * 
 * @author badqiu email:badqiu(a)gmail.com
 * @version 1.0
 * @since 1.0
 */
@Service("overviewBloomfilterService")
@Transactional
public class OverviewBloomfilterServiceImpl implements OverviewBloomfilterService {

	protected static final Logger log = LoggerFactory.getLogger(OverviewBloomfilterServiceImpl.class);
	
	//
	// 请删除无用的方法，代码生成器只是为你生成一个架子
	//
	
	private OverviewBloomfilterDao overviewBloomfilterDao;
	/**增加setXXXX()方法,spring就可以通过autowire自动设置对象属性,请注意大小写*/
	public void setOverviewBloomfilterDao(OverviewBloomfilterDao dao) {
		this.overviewBloomfilterDao = dao;
	}
	
	/** 
	 * 创建OverviewBloomfilter
	 **/
	public OverviewBloomfilter create(OverviewBloomfilter overviewBloomfilter) {
	    Assert.notNull(overviewBloomfilter,"'overviewBloomfilter' must be not null");
	    initDefaultValuesForCreate(overviewBloomfilter);
	    new OverviewBloomfilterChecker().checkCreateOverviewBloomfilter(overviewBloomfilter);
	    overviewBloomfilterDao.insert(overviewBloomfilter);
	    return overviewBloomfilter;
	}
	
	/** 
	 * 更新OverviewBloomfilter
	 **/	
    public OverviewBloomfilter update(OverviewBloomfilter overviewBloomfilter) {
        Assert.notNull(overviewBloomfilter,"'overviewBloomfilter' must be not null");
        //new OverviewBloomfilterChecker().checkUpdateOverviewBloomfilter(overviewBloomfilter);
        overviewBloomfilterDao.update(overviewBloomfilter);
        return overviewBloomfilter;
    }	
    
	/** 
	 * 删除OverviewBloomfilter
	 **/
    public void removeById(String bloomfilterGroup, String bloomfilterName, String partition) {
        overviewBloomfilterDao.deleteById(bloomfilterGroup,bloomfilterName, partition);
    }
    
	/** 
	 * 根据ID得到OverviewBloomfilter
	 **/    
    public OverviewBloomfilter getById(String bloomfilterGroup, String bloomfilterName) {
        return overviewBloomfilterDao.getById(bloomfilterGroup,bloomfilterName);
    }
    
	/** 
	 * 分页查询: OverviewBloomfilter
	 **/      
	@Transactional(readOnly=true)
	public Page<OverviewBloomfilter> findPage(OverviewBloomfilterQuery query) {
	    Assert.notNull(query,"'query' must be not null");
		return overviewBloomfilterDao.findPage(query);
	}
	
    
	/**
	 * 为创建时初始化相关默认值 
	 **/
    public void initDefaultValuesForCreate(OverviewBloomfilter overviewBloomfilter) {
    }
    
    /**
     * OverviewBloomfilter的属性检查类,根据自己需要编写自定义检查
     **/
    public class OverviewBloomfilterChecker {
        /**可以在此检查只有更新才需要的特殊检查 */
        public void checkUpdateOverviewBloomfilter(OverviewBloomfilter overviewBloomfilter) {
            checkOverviewBloomfilter(overviewBloomfilter);
        }
    
        /**可以在此检查只有创建才需要的特殊检查 */
        public void checkCreateOverviewBloomfilter(OverviewBloomfilter overviewBloomfilter) {
            checkOverviewBloomfilter(overviewBloomfilter);
        }
        
        /** 检查到有错误请直接抛异常，不要使用 return errorCode的方式 */
        public void checkOverviewBloomfilter(OverviewBloomfilter overviewBloomfilter) {
        	// Bean Validator检查,属性检查失败将抛异常
            //validateWithException(overviewBloomfilter);
            
        	//复杂的属性的检查一般需要分开写几个方法，如 checkProperty1(v),checkProperty2(v)
        }
    }

	@Override
	public List<OverviewBloomfilter> getByBloomFilterGroup(String bloomfilterGroup) {
		return overviewBloomfilterDao.getByBloomFilterGroup(bloomfilterGroup);
	}

	@Override
	public List<OverviewBloomfilter> getAll() {
		return overviewBloomfilterDao.getAll();
	}

	@Override
	public List<OverviewBloomfilter> getByServerIp(String serverIp) {
		return overviewBloomfilterDao.getByServerIp(serverIp);
	}

}
